package com.thesis.object;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * ListBill class
 * 
 * save many detail of bills
 * 
 * @author NgocTuyen
 *
 */
public class ListBill {
	//array list of many bills
	private ArrayList<Bill> listBills;
	
	/**
	 * Constructor function
	 * 
	 * Constructor
	 * 
	 * @access public 
	 * 
	 * @param null
	 * 
	 * @return null
	 */
	public ListBill(){
		listBills = new ArrayList<Bill>();
	}
	
	/**
	 * addBillByJson function
	 * 
	 * add all bill into list bills
	 * 
	 * @access public
	 * 
	 * @param listJson: list of many bills
	 * 
	 * @return void
	 */
	public void addBillByJson(JSONArray listJson){
		for (int i = 0; i < listJson.length(); i++) {
			try {
				addBill(listJson.getJSONObject(i));
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * addBill function
	 * 
	 * add a bill into list bill
	 * 
	 * @access private
	 * 
	 * @param jsonObj: json of one bill
	 * 
	 * @return void
	 */
	private void addBill(JSONObject jsonObj){
		try {
			Bill bill = new Bill(jsonObj.getInt("_id"), jsonObj.getInt("user_id"), jsonObj.getInt("bill_code"), jsonObj.getString("date"), jsonObj.getString("start_time"), jsonObj.getString("end_time"), jsonObj.getInt("table_id"), jsonObj.getString("feedback"), jsonObj.getInt("total_cost"));
			listBills.add(bill);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * getListBill function
	 * 
	 * get list many bills in restaurant
	 * 
	 * @access public
	 * 
	 * @param null
	 * 
	 * @return ArrayList<Bill>
	 *  + list of many bills
	 */
	public ArrayList<Bill> getListBill(){
		return listBills;
	}
}
